﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CanDoo;
using CanDoo.Core;
using CanDoo.Core.Data;
using CanDoo.Data;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Oil.Core.DTOs;
using CanDoo.Oil.Core.Models;

namespace CanDoo.Oil.Core.Services
{
    /// <summary>
    /// 业务实现——媒体广告
    /// </summary>
    public class MediaADService : CanDoo.Data.Entity.Services.ServiceBase<MediaAD>, IMediaADContract
    {
        public MediaADService()
        {
        
        }

        /// <summary>
        /// 1.1.17 查询媒体列表 输入媒体门店id、终端id查询媒体列表
        /// </summary>
        /// <param name="terminalKeyInfo"></param>
        /// <returns></returns>
        public List<MediaInfo> GetByTerminal(TerminalKeyInfo terminalKeyInfo)
        {
            using (DbScopeFactory.CreateReadOnly())
            {
                var mediaList = TrackEntities.Where(p=>p.IsDeleted == false).ToList();
                var list = new List<MediaInfo>();
                foreach (var m in mediaList)
                {
                    var entity = new MediaInfo();
                    entity.id = m.Id;
                    entity.name = m.Name;
                    entity.size = m.Size;
                    entity.format = "----";
                    entity.time = "0";
                    entity.mediaUrl = m.Url;
                    entity.createTime = m.CreatedTime.TimeToString("yyyy-MM-dd hh:mm:ss");
                    if(m.StartTime!=null)
                        entity.effectiveTime = m.StartTime.ToDateTime().TimeToString("yyyy-MM-dd hh:mm:ss");
                    if(m.EndTime!=null)
                        entity.endPlayTime = m.EndTime.ToDateTime().TimeToString("yyyy-MM-dd hh:mm:ss");
                    entity.updateTime = "null";
                    entity.failureTime = "null";
                    entity.md5 = m.MD5;
                    entity.startPlayTime = "null";
                    list.Add(entity);
                }
                return list;
            }
        }
    }
}
